package dungeonPackage;


import static org.junit.Assert.*;

import java.util.*;

import org.junit.*;

import squareBorderPackage.*;

/**
 * A class collecting tests for the class of singular dungeons.
 * 
 * @author Jessa Bekker & Esther Alberts
 * @version 1.0
 */
public class SingularDungeonTest {

	/**
	 * Class variables referencing singularDungeons that do not change during the
	 * entire test case.
	 */	
	private static SingularDungeon<AccessibleSquare> level, level2;
	
	/**
	 * Class variables referencing orientations that do not change during the
	 * entire test case.
	 */
	private static Orientation max, or1, or2, or3;
	
	/**
	 * Class variables referencing accessible squares that do not change during the
	 * entire test case.
	 */
	private static AccessibleSquare square1, square2, square3;
	
	/**
	 * Set up an immutable test fixture.
	 * 
	 * @post	The variable max references a new Orientation with coordinates (10,10,0)
	 * @post	The variable or1 references a new Orientation with coordinates (2,5,0)
	 * @post	The variable or2 references a new Orientation with coordinates (3,6,0)
	 * @post	The variable or3 references a new Orientation with coordinates (4,8,0)
	 * @post	The variable level references a new Level with maxCoordinates max
	 * @post	The variable level2 references a new Level with maxCoordinates max
	 * @post	The variables square1, square2, square3reference 
	 * 			a new NormalSquare with a temperature of 25 degree celsius and humidity of ten percent.
	 * @post	square1, square2 and square3 are set at the orientations or1, or2 and or3 in the Level level.
	 */
	@BeforeClass
	public static void setUpBeforeClass() {
		max = new Orientation(10,10,0);
		level = new Level<AccessibleSquare>(max);
		level2 = new Level<AccessibleSquare>(max);
		
		or1 = new Orientation(2,5,0);
		or2 = new Orientation(3,6,0);
		or3 = new Orientation(4,8,0);
		
		square1 = new NormalSquare();
		square2 = new NormalSquare();
		square3 = new NormalSquare();
		
		level.setSquareAt(or1, square1);
		level.setSquareAt(or2, square2);
		level.setSquareAt(or3, square3);
	}
	
	@Test
	public void sameCoordinates(){
		assertTrue(level.sameCoordinates(new Orientation(1,1,1)));
		assertFalse(level.sameCoordinates(new Orientation(1,2,1)));
	}

	@Test
	public void iterator_normal() {
		Set<Square> squares = new HashSet<Square>();
		Iterator<AccessibleSquare> iterator = level.iterator();
		while(iterator.hasNext()) {
			squares.add(iterator.next());
		}
		
		assertTrue(squares.contains(square1));
		assertTrue(squares.contains(square2));
		assertTrue(squares.contains(square3));
	}
	
	@Test
	public void iterator_noElements() {
		assertFalse(level2.iterator().hasNext());
	}
	
	@Test
	public void iterator_nullElement() {
		HashMap<Orientation, Square> squares = new HashMap<Orientation, Square>();
		squares.put(or1, null);
		Iterator<Square> iterator = squares.values().iterator();
		assertEquals(iterator.next(), null);
	}

}
